from typing import Dict
import requests

class DifyClient:
    def __init__(self, api_key: str):
        self.api_key = api_key
        self.base_url = "http://10.10.5.89/v1"
        self.headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        }
    
    def chat(self, query: str, inputs: Dict = None) -> Dict:
        """发送聊天请求
        Args:
            query: 查询内容
            inputs: 额外的输入参数
        """
        url = f"{self.base_url}/chat-messages"
        
        payload = {
            "inputs": inputs or {},
            "query": query,
            "response_mode": "blocking",
            "user": "test-analyzer"
        }
        
        response = requests.post(url, headers=self.headers, json=payload)
        response.raise_for_status()
        return response.json() 